<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/vue@next"></script>
</head>

<body>
    <!-- 爷孙传递数据，不管嵌套多少层，直达不需要多层传递 -->
    <div id="app"></div>
</body>
<script>
    let son = {
        inject: ['count'],
        template: `<div>子组件{{count}}</div>`
    }
    let father = {
        components: { son },
        template: `
                    <div>
                        父组件
                        <son />
                    </div>`,
    }
    //在Vue2.x中provide传递的数据是一次性的，初始化的时候传递，后续传递失效
    // Vue3.x解决了这个问题
    let vm = {
        components: { father },
        template: `
                    爷组件
                    <father></father>
                    <button @click="count++">点我</button>
                    `,
        provide: function () {
            return { count: this.count }
        },
        data () {
            return {
                count: 10
            }

        }
    }
    Vue.createApp(vm).mount('#app')
</script>

</html>